<template>
  <div>
    <el-form :model="form">
      <el-form-item label="账号" prop="username">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  
  import { mapMutations } from 'vuex'
  
  export default {
    data() {
      return {
        form: {
          username: '',
          password: ''
        }
      }
    },
    methods: {
      ...mapMutations(['setUser']),
      login() {
        this.setUser(this.form);
        let authorization = null;
        if (this.form.username == 'admin1') {
          authorization = [{
            path: '/admin1',
            name: 'admin1',
            meta: {
              name: '首页1',
              activeMenu: '/home'
            },
            component: 'admin1'
          }];
        } else {
          authorization = [{
            path: '/admin2',
            name: 'admin2',
            meta: {
              name: '首页2'
            },
            component: 'admin2'
          }];
        }
        sessionStorage.setItem('authorization', JSON.stringify(authorization));
        this.$router.push('/');
      }
    }
  }
</script>

<style>
</style>
